<template>
  <div class="template-index-Lu">
    <commpVxeTable
          :isCanWrap="true"
          :conditionBtnRow="true"
          :key="reCommpVxeTable"
          :config="dataTableConfig"
          :columns="columnsVxe"
          :formItem="formItem"
          @checkboxChange="checkboxChange"
          ref="administrativeOffice"
          @searchEvent="searchEvent"
          @resetEvent="resetEvent"
          >
          <template v-slot:externalOperations="{data}"  >
          <vxe-form-item>
              <template>
                  <a-button class="blue-btn" @click="batchJp">批量生成解聘登记</a-button>
              </template>
          </vxe-form-item>
      </template>
          <template v-slot:operation_realname="{row}" data-desc="姓名">
            <span style="padding-right: 21;" v-if="row.realname.length == 2">
                <span v-for="(trem,tI) in row.realname.split('')" :key="tI" >
                    {{trem}}
                    <span v-if="tI+1 !== row.realname.split('').length">&nbsp;&nbsp;</span>
                </span>
            </span>
            <span style="padding-right: 21;" v-else>{{ row.realname }}</span>
        </template>
          <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
              <a-form layout="inline">
                  <a-form-item v-if="row.fshzt == '已完成'">
                      <a-button class="green-btn" @click="reviseClick(row)" icon="eye">查看</a-button>
                  </a-form-item>
                  <a-form-item v-if="row.fshzt == '待审核'">
                      <a-button class="blue-btn" @click="reviseClick(row)" icon="edit">办理</a-button>
                  </a-form-item>
              </a-form>
          </template>
      </commpVxeTable>
      <increase ref="increaseRef" @success="success"></increase>
      <increaseJp ref="increaseJpRef" @success="success"></increaseJp>
  </div>
</template>
<script>
import  commpVxeTable   from '@/components/commp-vxe-table/commp-vxe-table.vue'
import  assessCheckApi  from './service/api'
import increase from './increase'
import increaseJp from './increaseJp.vue'
import {initSqjpToJpdj} from './service/index'
export default {
  components: {
      commpVxeTable,increase,increaseJp
  },
  data() {
    return {
          reCommpVxeTable: '',
          dataTableConfig: {
              api: assessCheckApi.queryJpPageList,
              rowId: 'id',
              paramet: {}
          },
          columnsVxe: [
              {
                  type: 'checkbox',
                  width: 60,
                  fixed: 'left'
              },{
                  title: '申请人',
                  field: 'realname',
                  width: 100,
                  slots: {
                  // 使用插槽模板渲染
                    default: 'operation_realname',
                  },
              },{
                  title: '工作单位',
                  field: 'fgzdw',
              },{
                  title: '申请时间',
                  field: 'ffqsj',
                  width: 130,
              },{
                  title: '申请类型',
                  field: 'fsqlx',
                  width: 100,
              },{
                  title: '原审评类型',
                  field: 'fyjcylb',
              },{
                  title: '申请审评类型',
                  field: 'fsqjcylb',
              },{
                  title: '是否已处理',
                  field: 'fsfycl',
                  width: 120,
              },{
                  title: '是否同意',
                  field: 'fsftysq',
                  width: 100,
              },{
                  title: '操作',
                  field: 'id',
                  width: 100,
                  titleInterval:true,
                  slots: {
                  // 使用插槽模板渲染
                      header:'data2_header',
                      default: 'operation_btn',
                  },
              }
          ],
          formItem: [
              {
                  label: '关键字',
                  model: 'gjz',
              },
          ],
          idList: [],
          formData: {},
      }
  },
  methods: {
      // 勾选
      checkboxChange(val){
          //console.log('已选择',val)
          this.idList = []
          if(val.length){
              val.forEach(item => {
                  this.idList.push(item.id)
              });
          }
      },
      // 搜索
      searchEvent(){
          this.dataTableConfig.paramet = {
              ...this.dataTableConfig.paramet,
          }
      },
      // 重置
      resetEvent(){
          //console.log('重置')
          this.reCommpVxeTable = Date.now()
          this.dataTableConfig.paramet = {
              ...this.dataTableConfig.paramet,
          }
      },
      downloadPdf(href){
        window.open(href,'_blank')
      },
      addhandle(){
        this.$nextTick(() => {
          this.$refs.increaseRef.increaseVisible = true
          this.$refs.increaseRef.getData()
        })
      },
      reviseClick(row){
        //console.log(row)
        this.$nextTick(() => {
          if( row.fshzt == '已完成'){
            // this.$refs.increaseRef.getNewData(row.id,3,true)
            // this.$refs.increaseRef.increaseVisible = true
            if(row.fsqlx == '解聘'){
              this.$refs.increaseJpRef.getNewData(row.id,true)
              this.$refs.increaseJpRef.increaseVisible = true
            } else {
              this.$refs.increaseRef.getNewData(row.id,3,true)
              this.$refs.increaseRef.increaseVisible = true
            }
          } else if(row.fshzt == '待审核') {
            if(row.fsqlx == '解聘'){
              this.$refs.increaseJpRef.getNewData(row.id,false)
              this.$refs.increaseJpRef.increaseVisible = true
            } else {
              this.$refs.increaseRef.getNewData(row.id,2,true)
              this.$refs.increaseRef.increaseVisible = true
            }
          }
        })
      },
      // 批量解聘
      batchJp(){
        if(this.idList.length <= 0){
          this.$message.warning('请勾选数据！')
          return
        }
        // this.$message.info('This is a normal message');
        initSqjpToJpdj({ids: this.idList.toString()}).then(res => {
          if(res.success){
            this.$message.success(res.message)
            this.$router.push({path:'/dismissalWithNumber/index'})
          } else {
            this.$message.warning(res.message)
          }
        })
      },
    // 弹窗关闭
    success(){
      // 刷新表格 清空id数组
      this.$refs.administrativeOffice.resetEvent()
      this.idList = []
    },
  },
}
</script>
